package com.dsh.userSetting.service.impl;

import com.dsh.userSetting.dao.AgreementDao;
import com.dsh.userSetting.entity.vo.*;
import com.dsh.userSetting.service.AgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AgreementServiceImpl implements AgreementService {
    @Autowired
    AgreementDao agreementDao;

    @Override
    public UserAgreementVo selectUserAgreement(UserAgreementVo userAgreementVo) {
        UserAgreementVo userAgreementVo1 = agreementDao.selectUserAgreement();
        if (userAgreementVo!=null){
            if (userAgreementVo1==null){
                this.agreementDao.insertUserAgreement(userAgreementVo);
            }
            else {
                this.agreementDao.updateUserAgreement(userAgreementVo);
            }
        }
        UserAgreementVo userAgreementVo2 = agreementDao.selectUserAgreement();
        return userAgreementVo2;
    }

    @Override
    public UserPrivacyVo selectUserPrivacy(UserPrivacyVo userPrivacyVo) {
        UserPrivacyVo userPrivacyVo1 = agreementDao.selectUserPrivacy();
        if (userPrivacyVo!=null){
            if (userPrivacyVo1==null){
                this.agreementDao.insertUserPrivacy(userPrivacyVo);
            }
            else {
                this.agreementDao.updateUserPrivacy(userPrivacyVo);
            }
        }
        UserPrivacyVo userPrivacyVo2 = agreementDao.selectUserPrivacy();
        return userPrivacyVo2;
    }

    @Override
    public UserRechargeVo selectUserRecharge(UserRechargeVo userRechargeVo) {
        UserRechargeVo userRechargeVo1 = agreementDao.selectUserRecharge();
        if (userRechargeVo!=null){
            if (userRechargeVo1==null){
                this.agreementDao.insertUserRecharge(userRechargeVo);
            }
            else {
                this.agreementDao.updateUserRecharge(userRechargeVo);
            }
        }
        UserRechargeVo userRechargeVo2 = agreementDao.selectUserRecharge();
        return userRechargeVo2;
    }

    @Override
    public UserLevelVo selectUserLevel(UserLevelVo userLevelVo) {
        UserLevelVo userLevelVo1 = agreementDao.selectUserLevel();
        if (userLevelVo!=null){
            if (userLevelVo1==null){
                this.agreementDao.insertUserLevel(userLevelVo);
            }
            else {
                this.agreementDao.updateUserLevel(userLevelVo);
            }
        }
        UserLevelVo userLevelVo2 = agreementDao.selectUserLevel();
        return userLevelVo2;
    }

    @Override
    public UserUpgradeVo selectUserUpgrade(UserUpgradeVo userUpgradeVo) {
        UserUpgradeVo userUpgradeVo1 = agreementDao.selectUserUpgrade();
        if (userUpgradeVo!=null){
            if (userUpgradeVo1==null){
                this.agreementDao.insertUserUpgrade(userUpgradeVo);
            }
            else {
                this.agreementDao.updateUserUpgrade(userUpgradeVo);
            }
        }
        UserUpgradeVo userUpgradeVo2 = agreementDao.selectUserUpgrade();
        return userUpgradeVo2;
    }

    @Override
    public List<ConditionsVo> selectAll() {
        List<ConditionsVo> conditionsVos = agreementDao.selectAll();
        return conditionsVos;
    }

    @Override
    public int insertRule(ConditionsVo conditionsVo) {
        int i = agreementDao.insertRule(conditionsVo);
        return i;
    }

    @Override
    public ConditionsVo selectAllById(int id) {
        ConditionsVo conditionsVo = agreementDao.selectAllById(id);
        return conditionsVo;
    }

    @Override
    public int updateRule(ConditionsVo conditionsVo) {
        int i = agreementDao.updateRule(conditionsVo);
        return i;
    }

    @Override
    public List<StrategyVo> selectAllStrategy() {
        List<StrategyVo> strategyVos = agreementDao.selectAllStrategy();
        return strategyVos;
    }

    @Override
    public List<RechargeAndGiftVo> selectRechargeAndGiftBySId(int sId) {
        List<RechargeAndGiftVo> rechargeAndGiftVos = agreementDao.selectRechargeAndGiftBySId(sId);
        return rechargeAndGiftVos;
    }
    @Override
    public void updateRechargeAndGift(List<RechargeAndGiftVo> rechargeAndGiftVos) {
        for (int i = 0; i <rechargeAndGiftVos.size() ; i++) {
            this.agreementDao.updateRechargeAndGift(rechargeAndGiftVos.get(i));
        }
    }
    @Override
    public List<AreaByAdminVo> selectAreaByAdminId(int uId) {
        List<AreaByAdminVo> areaByAdminVos = agreementDao.selectAreaByAdminId(uId);
        return areaByAdminVos;
    }

    @Override
    public List<StoreAndAreaVo> selectStoreByAreaId(int aId) {
        List<StoreAndAreaVo> storeAndAreaVos = agreementDao.selectStoreByAreaId(aId);
        return storeAndAreaVos;
    }

    @Override
    public void updateStrategyToStore(List<StoreAndAreaVo> storeAndAreaVos) {
        for (int i = 0; i <storeAndAreaVos.size() ; i++) {
            this.agreementDao.updateStrategyToStore(storeAndAreaVos.get(i));
        }
    }
}
